package com.haiertvbic.tvnow.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.haiertvbic.tvnow.R;
import com.haiertvbic.tvnow.model.ThridProgram;
import com.haiertvbic.tvnow.util.SLog;
import com.haiertvbic.tvnow.util.Util;

public class ResProgramAdapter extends BaseAdapter {
	private static final String TAG = "ResProgramAdapter";
	private ArrayList<ThridProgram> programJs;
	private Context context;

	public ResProgramAdapter(Context context, ArrayList<ThridProgram> programJs) {
		this.programJs = programJs;
		this.context = context;
	}

	@Override
	public int getCount() {
		return programJs.size();
	}

	@Override
	public Object getItem(int position) {
		return programJs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	class ViewHolder {
		TextView js;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = new ViewHolder();
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.pop_ott_js_item, null);
			holder.js = (TextView) convertView.findViewById(R.id.pop_js);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String content = programJs.get(position).getName();
		if (Util.isJs(programJs)) {
			content = programJs.get(position).getJs();
			holder.js.setGravity(Gravity.CENTER);
		}
		holder.js.setText(content);
		return convertView;
	}

}
